/**
 *
 *项目名：
 *包名：com.zhibaicc.android
 *文件名：DialogUtils.java
 *版本信息：1.0.0
 *创建日期：2014年5月30日-下午3:14:27
 *创建人： 单
 *上海智百文化传播有限公司
 */
package com.sensePlusVR.utils;

import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.graphics.Bitmap;
import android.text.Html;
import android.view.View;
import android.view.WindowManager;
import android.widget.EditText;
import android.widget.ImageView;

import com.sensePlusVR.main.R;

/**
 * 
 * @author: Loren
 * @create: 2016-7-4下午8:02:24
 * @desc:提示信息 
 *
 */
public class DialogUtils {

    /**
     * 
     * @param context
     * @param title
     *            标题
     * @param content
     *            提示内容
     * @param confirmClick
     *            确认
     * @param cancelClick
     *            取消
     */
    public static void showConfirmDialogConfirmCancel(Context context,
            String title, String content,
            DialogInterface.OnClickListener confirmClick,
            DialogInterface.OnClickListener cancelClick) {
        AlertDialog.Builder adb = new AlertDialog.Builder(context);
        adb.setTitle(title);
        adb.setMessage(content);
        adb.setPositiveButton(R.string.confirm, confirmClick);
        adb.setNegativeButton(R.string.cancel, cancelClick);
        adb.setCancelable(false);
        adb.show();
        // .setIcon(android.R.drawable.ic_dialog_info)
    }
        /**
         * 
         * @param context
         * @param title
         *            标题
         * @param content
         *            提示内容
         * @param confirmClick
         *            确认
         * @param cancelClick
         *            取消
         */
        public static void showConfirmDialogConfirmCancel(Context context,
                String title, String content,String comfirmBtnName,
                DialogInterface.OnClickListener confirmClick,String cancelBtnName,
                DialogInterface.OnClickListener cancelClick) {
            AlertDialog.Builder adb = new AlertDialog.Builder(context);
            adb.setTitle(title);
            adb.setMessage(content);
            adb.setPositiveButton(comfirmBtnName, confirmClick);
            adb.setNegativeButton(cancelBtnName, cancelClick);
            adb.setCancelable(false);
            adb.show();
            // .setIcon(android.R.drawable.ic_dialog_info)
        }

    /**
     * 
     * @param context
     * @param title
     *            标题
     * @param content
     *            提示内容
     * @param confirmClick
     *            确认
     */
    public static void showConfirmDialogConfirm(Context context, String title,
            String content, DialogInterface.OnClickListener confirmClick) {
        AlertDialog.Builder adb = new AlertDialog.Builder(context);
        adb.setTitle(title);
        adb.setMessage(content);
        adb.setPositiveButton(R.string.confirm, confirmClick);
        adb.setCancelable(false);
        adb.show();
    }
    
    /**
     * 
     * @param context
     * @param title
     *            标题
     * @param content
     *            提示内容
     * @param confirmClick
     *            确认
     */
    public static void showConfirmDialogConfirm(Context context, String title,
            String content,String btnText,DialogInterface.OnClickListener confirmClick) {
        AlertDialog.Builder adb = new AlertDialog.Builder(context);
        adb.setTitle(title);
        adb.setMessage(content);
        adb.setPositiveButton(btnText, confirmClick);
        adb.setCancelable(false);
        adb.show();
    }

    /**
     * 带输入框
     * 
     * @param context
     * @param title
     *            标题
     * @param content
     *            内容
     * @param confirmClick
     *            确定
     */
    public static void showDialogEditText(Context context, String title,
            String content, DialogInterface.OnClickListener confirmClick,
            DialogInterface.OnClickListener cancelClick) {
        AlertDialog.Builder adb = new AlertDialog.Builder(context);
        adb.setTitle(title);
        adb.setMessage(content);
        adb.setView(new EditText(context));
        adb.setPositiveButton(R.string.confirm, confirmClick);
        adb.setNegativeButton(R.string.cancel, cancelClick);
        adb.setCancelable(false);
        adb.show();

        // .setIcon(android.R.drawable.ic_dialog_info)
    }

    /**
     * 提示信息
     * 
     * @param context
     * @param title
     *            标题
     * @param content
     *            内容
     */
    public static void showDialog(Context context, String title, String content) {
        AlertDialog.Builder adb = new AlertDialog.Builder(context);
        adb.setTitle(title);
        adb.setMessage(content);
        adb.setPositiveButton(R.string.confirm, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int id) {
                dialog.cancel();
            }
        });
        adb.setCancelable(false);
        adb.show();
    }

    /**
     * 提示信息 确定-取消
     * 
     * @param context
     * @param title
     *            标题
     * @param content
     *            内容
     * @param clickListener
     *            确定事件
     */
    public static void showDialog(Context context, String title,
            String content, DialogInterface.OnClickListener clickListener) {
        AlertDialog.Builder adb = new AlertDialog.Builder(context);
        adb.setTitle(title);
        adb.setMessage(content);
        adb.setPositiveButton(R.string.confirm, clickListener);
        adb.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.cancel();
            }
        });
        adb.setCancelable(false);
        adb.show();
    }

    /**
     * 提示信息 带输入框
     * 
     * @param clickListener
     *            确定事件
     */
    public static void showDialogInput(Context context, EditText editText,
            DialogInterface.OnClickListener clickListener) {
        AlertDialog.Builder adb = new AlertDialog.Builder(context);
        //adb.setTitle(R.string.dialog_input);
        adb.setIcon(android.R.drawable.ic_dialog_info);
        adb.setView(editText);
        adb.setPositiveButton(R.string.confirm, clickListener);
        adb.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.cancel();
            }
        });
        adb.setCancelable(false);
        adb.show();
    }

    /**
     * 提示信息 带输入框
     * 
     * @param clickListener
     *            确定事件
     */
    public static void showDialogInput(Context context, String title,
            EditText editText, DialogInterface.OnClickListener clickListener) {
        AlertDialog.Builder adb = new AlertDialog.Builder(context);
        adb.setTitle(title);
        adb.setIcon(android.R.drawable.ic_dialog_info);
        adb.setView(editText);
        adb.setPositiveButton(R.string.confirm, clickListener);
        adb.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.cancel();
            }
        });
        adb.setCancelable(false);
        adb.show();
    }
    /**
     * 提示信息 带输入框
     * 
     * @param clickListener
     *            确定事件
     */
    public static void showDialogInput(Context context, String title,
            EditText editText, DialogInterface.OnClickListener clickListener,DialogInterface.OnClickListener cancleListener) {
        AlertDialog.Builder adb = new AlertDialog.Builder(context);
        adb.setTitle(title);
        adb.setIcon(android.R.drawable.ic_dialog_info);
        adb.setView(editText);
        adb.setPositiveButton(R.string.confirm, clickListener);
        adb.setNegativeButton(R.string.cancel, cancleListener);
        adb.setCancelable(false);
        adb.show();
    }

    /**
     * 提示信息 选择-单选
     * 
     * @param clickListener
     *            确定事件
     */
    public static void showDialogSelect(Context context, String items[],
            DialogInterface.OnClickListener clickListener) {
        AlertDialog.Builder adb = new AlertDialog.Builder(context);
        //adb.setTitle(R.string.dialog_select);
        adb.setIcon(android.R.drawable.ic_dialog_info);
        adb.setSingleChoiceItems(items, 0, clickListener);
        adb.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.cancel();
            }
        });
        adb.setCancelable(false);
        adb.show();
    }

    /**
     * 提示信息 选择-单选
     * 
     * @param clickListener
     *            确定事件
     */
    public static void showDialogSelect2(Context context, String items[],
            DialogInterface.OnClickListener clickListener) {
        AlertDialog.Builder adb = new AlertDialog.Builder(context);
        //adb.setTitle(R.string.dialog_select);
        adb.setIcon(android.R.drawable.ic_dialog_info);
        adb.setItems(items, clickListener);
        adb.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.cancel();
            }
        });
        adb.setCancelable(false);
        adb.show();
    }

    /**
     * 提示信息 选择-多选
     * 
     * @param clickListener
     *            确定事件
     */
    public static void showDialogs(Context context, String items[],
            DialogInterface.OnClickListener clickListener) {
        AlertDialog.Builder adb = new AlertDialog.Builder(context);
        //adb.setTitle(R.string.dialog_select);
        adb.setIcon(android.R.drawable.ic_dialog_info);
        adb.setMultiChoiceItems(items, null, null);
        adb.setPositiveButton(R.string.confirm, clickListener);
        adb.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.cancel();
            }
        });
        adb.setCancelable(false);
        adb.show();
    }

    /**
     * 提示信息 列表对话框
     * 
     * @param clickListener
     *            确定事件
     */
    public static void showDialog(Context context, String items[]) {
        AlertDialog.Builder adb = new AlertDialog.Builder(context);
        //adb.setTitle(R.string.dialog_list_box);
        adb.setIcon(android.R.drawable.ic_dialog_info);
        adb.setItems(items, null);
        adb.setNegativeButton(R.string.confirm, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.cancel();
            }
        });
        adb.setCancelable(false);
        adb.show();
    }

    /**
     * 提示信息 列表对话框
     * 
     * @param clickListener
     *            确定事件
     */
    public static void showDialog2(Context context, final String items[],
            final EditText editText) {
        AlertDialog.Builder adb = new AlertDialog.Builder(context);
        //adb.setTitle(R.string.dialog_list_box);
        adb.setIcon(android.R.drawable.ic_dialog_info);
        adb.setItems(items, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
                editText.setText(items[which]);
            }
        });
        // adb.setNegativeButton("确定", new DialogInterface.OnClickListener() {
        // public void onClick(DialogInterface dialog, int which) {
        // dialog.cancel();
        // }
        // });
        // adb.setOnItemSelectedListener(onItemSelectedListener);
        adb.setCancelable(false);
        adb.show();
    }

    /**
     * 提示信息 显示图片
     * 
     * @param clickListener
     *            确定事件
     */
    public static void showDialogImage(Context context, String items[],
            Bitmap bitmap) {
        ImageView img = new ImageView(context);
        img.setImageBitmap(bitmap);
        AlertDialog.Builder adb = new AlertDialog.Builder(context);
        //adb.setTitle(R.string.dialog_image_box);
        adb.setView(img);
        adb.setNegativeButton(R.string.confirm, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.cancel();
            }
        });
        adb.setCancelable(false);
        adb.show();
    }

    /**
     * 网络监测
     * 
     * @param context
     */
//    public static void NetWorkDialog(final Activity context) {
//        AlertDialog.Builder builder = new AlertDialog.Builder(context);
//       /builder.setTitle(R.string.dialog_tip)
//                .setMessage(R.string.dialog_network_failed)
//                .setPositiveButton(R.string.dialog_set_network,
//                        new DialogInterface.OnClickListener() {
//                            @Override
//                            public void onClick(DialogInterface arg0, int arg1) {
//                                Intent intent = new Intent(
//                                        Settings.ACTION_DATA_ROAMING_SETTINGS);
//                                ComponentName cname = new ComponentName(
//                                        "com.android.phone",
//                                        "com.android.phone.Settings");
//                                intent.setComponent(cname);
//                                context.startActivity(intent);
//                                context.finish();
//                            }
//                        })
//                .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
//                    @Override
//                    public void onClick(DialogInterface dialog, int which) {
//                        context.finish();
//                    }
//                }).show();
//    }

    /**
     * 自定义的ProgressDialog对话框进行的处理
     */
    public static ProgressDialog getCustomProgressDialog(Context context,
            String content) {
        ProgressDialog progressDialog = new ProgressDialog(context);
        progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
        progressDialog.setMessage(content);
        progressDialog.setCanceledOnTouchOutside(false);
        return progressDialog;
    }

    /**
     * 选择对话框
     * 
     * @param context
     *            上下文
     * @param title
     *            标题
     * @param content
     *            说明内容
     * @param positiveStr
     *            确认文字信息
     * @param positiveClick
     *            确认处理
     * @param negativeStr
     *            取消文字信息
     * @param cancelClick
     *            取消处理
     */
    public static void showSelectDialog(Context context, String title,
            String content, String positiveStr,
            DialogInterface.OnClickListener positiveClick, String negativeStr,
            DialogInterface.OnClickListener cancelClick) {
        AlertDialog.Builder adb = new AlertDialog.Builder(context);
        adb.setTitle(title);
        adb.setMessage(content);
        adb.setPositiveButton(positiveStr, positiveClick);
        adb.setNegativeButton(negativeStr, cancelClick);
        adb.setCancelable(false);
        adb.show();
    }

    /**
     * 选择对话框
     * 
     * @param context
     *            上下文
     * @param title
     *            标题
     * @param content
     *            说明内容
     * @param positiveStr
     *            确认文字信息
     * @param positiveClick
     *            确认处理
     * @param negativeStr
     *            取消文字信息
     */
    public static void showSelectDialog(Context context, String title,
            String content, String positiveStr,
            DialogInterface.OnClickListener positiveClick, String negativeStr) {
        AlertDialog.Builder adb = new AlertDialog.Builder(context);
        adb.setTitle(title);
        adb.setMessage(content);
        adb.setPositiveButton(positiveStr, positiveClick);
        if(StringUtils.isBlank(negativeStr)){
            negativeStr = context.getResources().getString(R.string.cancel);
        }
        adb.setNegativeButton(negativeStr,
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                    }
                });
        adb.setCancelable(false);
        adb.show();
    }

    /**
     * 提示信息
     * 
     * @param context
     * @param title
     * @param content
     */
    public static void showPromptDialog(Context context, String title,
            String content) {
        AlertDialog.Builder adb = new AlertDialog.Builder(context);
        adb.setTitle(title);
        adb.setMessage(content);
        adb.setPositiveButton(R.string.confirm, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
            }
        });
        adb.setCancelable(false);
        adb.show();
    }

    /**
     * 系统选择对话框
     * 
     * @param context
     *            上下文
     * @param title
     *            标题
     * @param content
     *            说明内容
     * @param positiveStr
     *            确认文字信息
     * @param positiveClick
     *            确认处理
     * @param negativeStr
     *            取消文字信息
     */
    public static void showSysSelectDialog(Context context, String title,
            String content, String positiveStr,
            DialogInterface.OnClickListener positiveClick, String negativeStr) {
        AlertDialog.Builder adb = new AlertDialog.Builder(context);
        adb.setTitle(title);
        adb.setMessage(content);
        adb.setPositiveButton(positiveStr, positiveClick);
        adb.setNegativeButton(negativeStr,
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                    }
                });
        AlertDialog dialog = adb.create();
        dialog.getWindow()
                .setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
        dialog.show();
    }

    /**
     * 系统提示信息
     * 
     * @param context
     * @param title
     * @param content
     */
    public static void showSysPromptDialog(Context context, String title,
            String content) {
        AlertDialog.Builder adb = new AlertDialog.Builder(context);
        adb.setTitle(title);
        adb.setMessage(content);
        adb.setPositiveButton(R.string.confirm, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
            }
        });
        AlertDialog dialog = adb.create();
        dialog.getWindow()
                .setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
        dialog.show();
    }

    /**
     * 自定义视图的弹框
     */

    public static void showCustomDialog(Context context, View v,
            String confirmName, String cancleName,
            DialogInterface.OnClickListener positiveClick,
            DialogInterface.OnClickListener negativeClick) {
        AlertDialog.Builder adb = new AlertDialog.Builder(context);
        adb.setTitle(Constant.STR_EMPTY);
        // adb.setMessage(content);
        adb.setView(v);
        adb.setPositiveButton(Html.fromHtml(confirmName), positiveClick);
        adb.setNegativeButton(Html.fromHtml(cancleName), negativeClick);
        // AlertDialog dialog = adb.create();
        // dialog.getWindow()
        // .setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
        adb.setCancelable(false);
        adb.show();
    }
    
    /**
     * 自定义视图的弹框
     */

    public static void showCustomDialog(Context context,String title,View v,
            String confirmName, String cancleName,
            DialogInterface.OnClickListener positiveClick,
            DialogInterface.OnClickListener negativeClick) {
        AlertDialog.Builder adb = new AlertDialog.Builder(context);
        adb.setTitle(title);
        // adb.setMessage(content);
        adb.setView(v);
        adb.setPositiveButton(Html.fromHtml(confirmName), positiveClick);
        adb.setNegativeButton(Html.fromHtml(cancleName), negativeClick);
        // AlertDialog dialog = adb.create();
        // dialog.getWindow()
        // .setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
        adb.setCancelable(false);
        adb.show();
    }
    
    
    /**
     * 自定义视图的弹框
     */
    public static void showCustomDialog(Context context,String title,View v,
            String confirmName, DialogInterface.OnClickListener positiveClick) {
        AlertDialog.Builder adb = new AlertDialog.Builder(context);
        adb.setTitle(title);
        // adb.setMessage(content);
        adb.setView(v);
        adb.setPositiveButton(Html.fromHtml(confirmName), positiveClick);
        // AlertDialog dialog = adb.create();
        // dialog.getWindow()
        // .setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
        adb.setCancelable(false);
        adb.show();
    }

}
